package com.ellington.controller;

import com.ellington.model.Job;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * Created by wuganlin on 2017/8/24.
 */
@Controller
public class IndexController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {

        List<Job> list = new ArrayList<>();
        list.add(generateJob("s425676a-cad","李白"));
        list.add(generateJob("s425677a-cad","杜甫"));
        list.add(generateJob("s425678a-cad","李贺"));
        list.add(generateJob("s425679a-cad","白居易"));
        list.add(generateJob("s425688a-cad","王维"));
        list.add(generateJob("s425699a-cad","王昌龄"));

        model.addAttribute("jobs",list);
        return "index";
    }


    private Job generateJob(String name, String maker){
        Job job = new Job();
        job.setMaker(maker);
        job.setName(name);
        job.setNew(true);
        job.setTime(new Date());
        return job;
    }
}
